PostgreSQL 9.6 : Install
2017/10/31 |
The version of PostgreSQL in CentOS 7 repository is 9.2 but Install 9.6 with RPM package if you need.
|
|
[1] | It's possible to install from CentOS SCLo Software Collections. It's OK to install it even if 9.2 is already installed because 9.6 is located on another PATH. |
# install from SCLo [root@www ~]# yum --enablerepo=centos-sclo-rh -y install rh-postgresql96-postgresql-server
|
[2] | Packages from Software Collections are installed uder the /opt directory. To use it, Load environment variables like follows. |
# load environment variables [root@www ~]# scl enable rh-postgresql96 bash
[root@www ~]#
[root@www ~]# postgres -V postgres (PostgreSQL) 9.6.5 which postgres /opt/rh/rh-postgresql96/root/usr/bin/postgres |
[3] | If you'd like to enable PostgreSQL 9.6 automatically at login time, configure like follows. |
[root@www ~]#
vi /etc/profile.d/rh-postgresql96.sh # create new #!/bin/bash source /opt/rh/rh-postgresql96/enable export X_SCLS="`scl enable rh-postgresql96 'echo $X_SCLS'`" |
[4] | Enable PostgreSQL 9.6 and start PostgreSQL Server. |
[root@www ~]#
postgresql-setup --initdb --unit rh-postgresql96-postgresql * Initializing database in '/var/opt/rh/rh-postgresql96/lib/pgsql/data' * Initialized, logs are in /var/lib/pgsql/initdb_rh-postgresql96-postgresql.log
[root@www ~]#
vi /var/opt/rh/rh-postgresql96/lib/pgsql/data/postgresql.conf # line 59: uncomment and change if allow accesses from remote hosts listen_addresses = ' * '
# line 433: uncomment and change if change log format log_line_prefix = ' %t %u %d '
systemctl start rh-postgresql96-postgresql [root@www ~]# systemctl enable rh-postgresql96-postgresql |
[5] | If Firewalld is running and also PostgreSQL is used from remote Hosts, allow service like follows. |
[root@www ~]# firewall-cmd --add-service=postgresql --permanent success [root@www ~]# firewall-cmd --reload success |
[6] | Set PostgreSQL admin user's password and add a user and also add a test database. |
# set password [root@www ~]# su - postgres -bash-4.2$ psql -c "alter user postgres with password 'password'" ALTER ROLE # add DB user [cent] as an example -bash-4.2$ createuser cent
# create a test database (owner is the user above) -bash-4.2$ createdb testdb -O cent
|
[7] | Login as a user just added above and operate DataBase as test operation. |
# show Databases [cent@www ~]$ psql -l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres testdb | cent | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows) # connect to test DB [cent@www ~]$ psql testdb
psql (9.6.5)
Type "help" for help.
# set password testdb=# alter user cent with password 'password'; ALTER ROLE # create a test table testdb=# create table testTable ( no int,name text ); CREATE TABLE # insert test data testdb=# insert into testTable (no,name) values (1,'cent'); INSERT 0 1 # show tables testdb=# select * from testTable;
no | name ----+------ 1 | cent (1 row) # delete test table testdb=# drop table testTable; DROP TABLE # quit testdb=# \q
# delete test database [cent@www ~]$ dropdb testdb
|